home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.7 KB | 311 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCursor.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWRESFIL_K
- #include "FWResFil.k"
- #endif
-
- #ifndef FWRESFIL_H
- #include "FWResFil.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__LOWMEM__)
- #include <LowMem.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwosmisc
- #endif
-
- //========================================================================================
- // CLASS FW_CCursor
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::FW_CCursor
- //----------------------------------------------------------------------------------------
- // Create an arrow cursor
-
- FW_CCursor::FW_CCursor() :
- fCursorHandle(NULL),
- fFromSystem(TRUE),
- fCursorID(0),
- #ifdef FW_BUILD_WIN
- fDeferred(TRUE),
- fSystemCursorID(IDC_ARROW)
- #endif
- #ifdef FW_BUILD_MAC
- fDeferred(FALSE),
- fMacIsColor(FALSE)
- #endif
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::FW_CCursor
- //----------------------------------------------------------------------------------------
- // Loads (immediatly) the cursor from the specified resources file
-
- FW_CCursor::FW_CCursor(FW_CResourceFile& resourceFile,
- FW_ResourceId resId) :
- fCursorHandle(NULL),
- fDeferred(FALSE)
- {
- PrivLoadCursor(resourceFile, resId);
-
- FW_END_CONSTRUCTOR
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CCursor::FW_CCursor
- //----------------------------------------------------------------------------------------
- // Loads (differed) the system cursor that has the specified ID.
-
- FW_CCursor::FW_CCursor(FW_SystemCursorID systemCursorId) :
- fCursorHandle(NULL),
- fDeferred(TRUE),
- fFromSystem(TRUE),
- fCursorID(0),
- fSystemCursorID(systemCursorId)
- {
- FW_END_CONSTRUCTOR
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::FW_CCursor
- //----------------------------------------------------------------------------------------
- // Loads (differed) a cursor from the system or this dll.
-
- FW_CCursor::FW_CCursor(FW_ResourceId resId, FW_Boolean fromSystem) :
- fCursorHandle(NULL),
- fDeferred(TRUE),
- fFromSystem(fromSystem)
- #ifdef FW_BUILD_WIN
- ,fSystemCursorID(NULL)
- #endif
- {
- fCursorID = resId;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::~FW_CCursor
- //----------------------------------------------------------------------------------------
-
- FW_CCursor::~FW_CCursor()
- {
- FW_START_DESTRUCTOR
-
- if (fCursorHandle != NULL)
- {
- #ifdef FW_BUILD_MAC
- if(fMacIsColor)
- ::DisposeCCursor((CCrsrHandle)fCursorHandle);
- else
- ::DisposeHandle((FW_PlatformHandle)fCursorHandle);
- #endif
- #ifdef FW_BUILD_WIN
- ::DestroyCursor(fCursorHandle);
- #endif
- }
-
- fCursorHandle = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::PrivLoadSystemCursor
- //----------------------------------------------------------------------------------------
- // Loads the system cursor that has the specified ID.
-
- void FW_CCursor::PrivLoadSystemCursor(FW_SystemCursorID systemCursorId)
- {
- // do not use the resource component because we're loading from the system
-
- #ifdef FW_BUILD_MAC
- // try a mono cursor first
- fCursorHandle = ::GetCursor(systemCursorId);
- fMacIsColor = FALSE;
-
- if (fCursorHandle == NULL)
- {
- // no mono cursor, try a color cursor
- fCursorHandle = (FW_PlatformCursorHandle) ::GetCCursor(systemCursorId);
- fMacIsColor = TRUE;
- }
-
- if (fCursorHandle == NULL)
- {
- FW_Failure(FW_xResourceNotFound);
- }
- else
- {
- // ----- We need to detache the resource because of CFM -----
- ::DetachResource((FW_PlatformHandle)fCursorHandle);
- ::HNoPurge((FW_PlatformHandle)fCursorHandle); // The resource may have been tagged purgeable
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- fCursorHandle = ::LoadCursor(NULL, systemCursorId);
-
- if (fCursorHandle == NULL)
- {
- FW_Failure(FW_xResourceNotFound);
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::PrivLoadCursor
- //----------------------------------------------------------------------------------------
- // Loads the cursor from the specified resources file
-
- void FW_CCursor::PrivLoadCursor(FW_CResourceFile& resourceFile,
- FW_ResourceId resId)
- {
- #ifdef FW_BUILD_MAC
- if(resourceFile.PrivHasSpecialResource(resId, FW_kCursor))
- {
- fMacIsColor = TRUE;
- fCursorHandle = (FW_PlatformCursorHandle)resourceFile.PrivGetSpecialResource(resId, FW_kCursor);
- }
- else
- {
- fMacIsColor = FALSE;
- fCursorHandle = (FW_PlatformCursorHandle)resourceFile.PrivGetSpecialResource(resId, FW_kBlackWhiteCursor);
- }
-
- // ----- We need to detache the resource because of CFM -----
- ::DetachResource((FW_PlatformHandle)fCursorHandle);
- ::HNoPurge((FW_PlatformHandle)fCursorHandle); // The resource may have been tagged purgeable
- #endif
-
- #ifdef FW_BUILD_WIN
- fCursorHandle = (FW_PlatformCursorHandle) resourceFile.PrivGetSpecialResource(resId, FW_kCursor);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::Select
- //----------------------------------------------------------------------------------------
-
- void FW_CCursor::Select() const
- {
- FW_CCursor* self = (FW_CCursor*)this;
- self->PrivDeferredLoad();
-
- #ifdef FW_BUILD_MAC
- if (fCursorHandle != NULL)
- {
- if(fMacIsColor)
- ::SetCCursor((CCrsrHandle)fCursorHandle);
- else
- ::SetCursor(*fCursorHandle);
- }
- else
- ::SetCursor(&FW_QDGlobals.arrow);
-
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_ASSERT(fCursorHandle != NULL);
- ::SetCursor(fCursorHandle);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::PrivDeferredLoad
- //----------------------------------------------------------------------------------------
-
- void FW_CCursor::PrivDeferredLoad()
- {
- if (fDeferred)
- {
- #ifdef FW_BUILD_MAC
- if (fFromSystem)
- PrivLoadSystemCursor(fCursorID);
- else
- {
- FW_CSharedLibraryResourceFile resFile;
- PrivLoadCursor(resFile, fCursorID);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- if (fFromSystem)
- PrivLoadSystemCursor(fSystemCursorID);
- else
- {
- FW_CSharedLibraryResourceFile resFile;
- PrivLoadCursor(resFile, fCursorID);
- }
- #endif
- fDeferred = FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCursor::GetHandle
- //----------------------------------------------------------------------------------------
- // On the Mac returns NULL for this arrow cursor
-
- FW_PlatformCursorHandle FW_CCursor::GetHandle() const
- {
- FW_CCursor* self = (FW_CCursor*)this;
- self->PrivDeferredLoad();
-
- #ifdef FW_BUILD_WIN
- FW_ASSERT(fCursorHandle);
- #endif
-
- return fCursorHandle;
- }
-
-